// example/ship/ship.js
var app = getApp()
import * as Api from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderId:'',
    shipList:[],
    shipStatus:'派送中',
    shipper_code:'',
    traces:[]
  },
  telShip:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.shipList.mobile //仅为示例，并非真实的电话号码
    })
  },
  handleShipCode(row) {
    switch (row) {
      case "AJ":
        return "安捷快递";
      case "ANE":
        return "安能物流";
      case "AXD":
        return "安信达快递";
      case "BQXHM":
        return "北青小红帽";
      case "BFDF":
        return "百福东方";
      case "BTWL":
        return "百世快运";
      case "CCES":
        return "CCES快递";
      case "CITY100":
        return "城市100";
      case "COE":
        return "COE东方快递";
      case "CSCY":
        return "长沙创一";
      case "CDSTKY":
        return "成都善途速运";
      case "DBL":
        return "德邦";
      case "DSWL":
        return "D速物流";
      case "DTWL":
        return "大田物流";
      case "EMS":
        return "EMS";
      case "FAST":
        return "快捷速递";
      case "FEDEX":
        return "FEDEX联邦(国内件）";
      case "FEDEX_GJ":
        return "FEDEX联邦(国际件）";
      case "FKD":
        return "飞康达";
      case "GDEMS":
        return "广东邮政";
      case "GSD":
        return "共速达";
      case "GTO":
        return "国通快递";
      case "GTSD":
        return "高铁速递";
      case "HFWL":
        return "汇丰物流";
      case "HHTT":
        return "天天快递";
      case "HLWL":
        return "恒路物流";
      case "HOAU":
        return "天地华宇";
      case "hq568":
        return "华强物流";
      case "HTKY":
        return "百世快递";
      case "HXLWL":
        return "华夏龙物流";
      case "HYLSD":
        return "好来运快递";
      case "JGSD":
        return "京广速递";
      case "JIUYE":
        return "九曳供应链";
      case "JJKY":
        return "佳吉快运";
      case "JLDT":
        return "嘉里物流";
      case "JTKD":
        return "捷特快递";
      case "JXD":
        return "急先达";
      case "JYKD":
        return "晋越快递";
      case "JYM":
        return "加运美";
      case "JYWL":
        return "佳怡物流";
      case "KYWL":
        return "跨越物流";
      case "LB":
        return "龙邦快递";
      case "LHT":
        return "联昊通速递";
      case "MHKD":
        return "民航快递";
      case "MLWL":
        return "明亮物流";
      case "NEDA":
        return "能达速递";
      case "PADTF":
        return "平安达腾飞快递";
      case "QCKD":
        return "全晨快递";
      case "QFKD":
        return "全峰快递";
      case "QRT":
        return "全日通快递";
      case "RFD":
        return "如风达";
      case "SAD":
        return "赛澳递";
      case "SAWL":
        return "圣安物流";
      case "SBWL":
        return "盛邦物流";
      case "SDWL":
        return "上大物流";
      case "SF":
        return "顺丰快递";
      case "SFWL":
        return "盛丰物流";
      case "SHWL":
        return "盛辉物流";
      case "ST":
        return "速通物流";
      case "STO":
        return "申通快递";
      case "STWL":
        return "速腾快递";
      case "SURE":
        return "速尔快递";
      case "TSSTO":
        return "唐山申通";
      case "UAPEX":
        return "全一快递";
      case "UC":
        return "优速快递";
      case "WJWL":
        return "万家物流";
      case "WXWL":
        return "万象物流";
      case "XBWL":
        return "新邦物流";
      case "XFEX":
        return "信丰快递";
      case "XYT":
        return "希优特";
      case "XJ":
        return "新杰物流";
      case "YADEX":
        return "源安达快递";
      case "YCWL":
        return "远成物流";
      case "YD":
        return "韵达快递";
      case "YDH":
        return "义达国际物流";
      case "YFEX":
        return "越丰物流";
      case "YFHEX":
        return "原飞航物流";
      case "YFSD":
        return "亚风快递";
      case "YTKD":
        return "运通快递";
      case "YTO":
        return "圆通速递";
      case "YXKD":
        return "亿翔快递";
      case "YZPY":
        return "邮政平邮/小包";
      case "ZENY":
        return "增益快递";
      case "ZHQKD":
        return "汇强快递";
      case "ZJS":
        return "宅急送";
      case "ZTE":
        return "众通快递";
      case "ZTKY":
        return "中铁快运";
      case "ZTO":
        return "中通速递";
      case "ZTWL":
        return "中铁物流";
      case "ZYWL":
        return "中邮物流";
      case "AMAZON":
        return "亚马逊物流";
      case "SUBIDA":
        return "速必达物流";
      case "RFEX":
        return "瑞丰速递";
      case "QUICK":
        return "快客快递";
      case "CJKD":
        return "城际快递";
      case "CNPEX":
        return "CNPEX中邮快递";
      case "HOTSCM":
        return "鸿桥供应链";
      case "HPTEX":
        return "海派通物流公司";
      case "AYCA":
        return "澳邮专线";
      case "PANEX":
        return "泛捷快递";
      case "PCA":
        return "PCA Express";
      case "UEQ":
        return "UEQ Express";
    }
  },
  getShipList(){
    let self = this
    let url = app.globalData.baseUrl1 + '/order/transport/userquery'
    let data = {
      token: app.globalData.token,
      userId: app.globalData.userId,
      orderId: this.data.orderId
    }
    let callBack = (res) => {
      if (res == null) {

        console.log("网络请求错误1！");
        return;
      }

      if (res.data.status != 200) {
        return
      }
      let traces = []
      for (let i = res.data.data.traces.length-1 ; i>0;i--){
          console.log()
          if (res.data.data.traces[i].AcceptStation.indexOf('已签收') != -1){
            this.setData({
              shipStatus:'已签收'
            })
          }
          traces.push(res.data.data.traces[i])
      }
      let opt = this.handleShipCode(res.data.data.shipper_code)
      this.setData({
        shipList: res.data.data,
        traces: traces,
        shipper_code:opt
      })


    }
    Api.reqFormPost(url, data, callBack)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.hideShareMenu()
    if (app.globalData.merchant === null) {
      app.doLogin(this.onLoad, this.onShow, options);
      return
    }
    this.setData({
      orderId: options.orderid
    })
    this.getShipList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})